package com.bainarm.library_public_utils;
import android.content.Context;
import android.content.SharedPreferences;

// shred preferences 的方法封装
// 保含登录状态的一些方法
public class SharedPreferencesDataStorageUtils {

    private String PREFERENCES_NAME;
    private Context context;

    public SharedPreferencesDataStorageUtils(Context context, String preferencesName) {
        this.context = context;
        this.PREFERENCES_NAME = preferencesName;
    }

    // 保存数据的方法
    public void saveData(String key, String value) {
        SharedPreferences sharedPref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString(key, value);
        editor.apply();
    }

    // 读取数据态方法
    public String loadData(String key, String defaultValue) {
        SharedPreferences sharedPref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
        return sharedPref.getString(key, defaultValue);
    }
}
